package com.liugui.springbootexceptionhandler.config;

import com.liugui.springbootexceptionhandler.exception.BusinessException;
import com.liugui.springbootexceptionhandler.exception.SystemException;
import com.liugui.springbootexceptionhandler.vo.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName: ExceptionControllerAdvice
 * @Author: liugui
 * @Date: 2020-06-25 21:53
 **/
@RestControllerAdvice
public class ExceptionControllerAdvice {

    /**
     * 业务逻辑异常。
     *  HTTP响应状态为200
     * @param businessException
     * @return
     */
    @ExceptionHandler(value = BusinessException.class)
    public ResultVO businessExceptionHandler(BusinessException businessException) {
        ResultVO result = businessException.getResult();
        return new ResultVO(result, 1000);
    }

    /**
     * 系统异常。
     *  HTTP响应状态为400
     * @param systemException
     * @return
     */
    @ExceptionHandler(value = SystemException.class)
    public ResultVO systemExceptionHandler(SystemException systemException) {
        ResultVO result = systemException.getResult();
        return new ResultVO(result, 400);
    }

}
